<?php 

/*
 * 检查用户登陆状态
 */
if(!function_exists('is_login')){
	function is_login(){
		$isLogin = false;
		$loginCookie = trim(cookie('_pdlfctunion'));
		if(isset($loginCookie) && $loginCookie){
			if(!session('loginUid') || !session('loginName')){
				return false;exit;
			}
			$isLogin = true;
		}
		
		return $isLogin;
	}
}

/*
 * 获取登陆用户的登陆信息
 */
if(!function_exists('getLoginMsg')){
	function getLoginMsg(){
		global $isLogin;
		$loginMsgObj = new stdClass();
		$loginMsgObj->isLogin = $isLogin;
		$loginMsgObj->username = base64_decode(substr(cookie('ajwUid'),0,-1));
		$users = M('ResEntity')->where(array('username'=>$loginMsgObj->username))->find();
		$loginMsgObj->rid = $users['rid'];
		$loginMsgObj->email = $users['email'];
		
		return $loginMsgObj;
	}
}

/*
 * 返回随机字符串
 */
if(!function_exists('randstr')){
	function randstr($num=1){
		$return = '';
		$randstr = '1023456789abcdefghijklmnopqrstuvwxyz';
		for($i=0;$i<$num;$i++){
			$return .= $randstr{rand(0,35)};
		}
		
		return $return;
	}
}



/*
 * 日志添加记录
 */
if(!function_exists('putlog')){
	function putlog($msg,$controller,$fun){
		M('SysLogs')->add(array(
			'sys_controller_name' => $controller,
			'sys_function_name' => $fun,
			'sys_remark' => (I('post.username') ? I('post.username') : '').$msg,
			'sys_editor' => '8899899'.session('loginUid'),
			'add_at' => time(),
			'update_at' => time()
		));
	}
}




?>